package ControlLayer;
import ModelLayer.*;
/**
 * This the Controller of the class Order. it contains info about a costumer, order, product and an employee.
 * 
 * @author Team Black 
 * @version 1.0
 */
public class OrdreCtr
{
    // instance variables - replace the example below with your own
    private PersonCtr personCtr;
    private ProductCtr productCtr;
    private OrdreLibrary orderLibrary;
    private Ordre order;
    private PartOrdre partOrder;

    /**
     * Constructor for objects of class OrdreCtr
     */
    public OrdreCtr()
    {
        orderLibrary = orderLibrary.getInstance(); 
    }
    /**
     * Creates a order, it is an emptyorder.
     */
    public Ordre createOrder()
    {
        order = new Ordre();
        orderLibrary.addOrdre(order);
        return order;
    }
    
    /**
     * search for employee by the ID
     */
    public Employee searchEmployeeById(int _id)
    {
        return personCtr.searchEmployeeById(_id);
    }
    /**
     * adds an object of employee to the employee list.
     */
    public void addEmployee(Employee _employee)
    {
        order.setEmployee(_employee);
    }
    /**
     * search for a product by an ID
     */
    public Product searchProductById(int _id)
    {
        return productCtr.searchProductById(_id);
    }
    /**
     * search for a product by an name
     */
    public Product searchProductByName(String _name)
    {
        return productCtr.searchProductByName(_name);
    }
    /**
     * Creates a new Partorder
     */
    public PartOrdre createPartOrder(Product _product)
    {
        partOrder = new PartOrdre();
        partOrder.setProduct(_product);
        return partOrder;
    }
    /**
     * adds a partorder to a given order
     */
    public void addPartOrder(PartOrdre _partOrder)
    {
        order.addPartOrdre(_partOrder);
    }
    /**
     * removes a partorder from a given order
     */
    public void removePartOrder(PartOrdre _partOrder)
    {
        order.removePartOrdre(_partOrder);
    }
    /**
     * search for a costumer by the ID
     */
    public Customer searchCustomerById(int _id)
    {
        return personCtr.searchCustomerById(_id);
    }
    /**
     * search for a costumer by the Name
     */
    public Customer searchCustomerByName(String _name)
    {
        return personCtr.searchCustomerByName(_name);
    } 
    /**
     * adds a costumer to a given order
     */
     public void addCustomer(Customer _customer)
    {
        order.setCustomers(_customer);
    }
    /**
     * adds a order to the library
     */
    public void addOrder(Ordre _order)
    {
        orderLibrary.addOrdre(_order);
    }
    /**
     * returns an order, by searching for a ID.
     */
    public Ordre getOrdreById(int _orderId)
    {
        Ordre currOrdre = orderLibrary.searchOrdreById(_orderId);
        return currOrdre;
    }
    
}
